<template>
	<view>
		<view style="background-color: #8F8F94;height: 350upx;">
			<image class="headerPortrait" style="width: 80upx;height: 80upx;" :src="user.headerPortraitUrl"></image>
			<view class="personMessage">
				<text v-text="user.nickname"></text>
				<text>|</text>
				<text v-text="user.sex==1?'男':'女'"></text>
			</view>
			<view style="text-align: center;"></view>
			<view class="fans">
				<text v-text="user.sex==1?'他':'她'"></text>
				<text>的粉丝：{{user.fansCount}}</text>
				<text>|</text>
				<text v-text="user.sex==1?'他':'她'"></text>
				<text>的关注：{{user.focusCount}}</text>
			</view>
		</view>
		<view class="list" v-if="isExistPostList">
			<view class="flex_row border" v-for="(post,index) in postList" @tap="toShowPostDetail(post.postId)" :key="index">
				<view class="flex_col">
					<image class="smallHeaderPortrait" :src="user.headerPortraitUrl" />
					<text style="padding-left: 50rpx;">{{user.nickname}}</text>
					<text style="font-size: small;padding-left: 50rpx;">{{post.postTime}}</text>
				</view>
				<view class="flex_col">
					<text class="postContent">{{post.postTitle}}</text>
				</view>
				<view class="flex_col" style="margin-left: 5%;">
					<image style="width:180upx ;height: 180upx;" :src="post.postImgList[0]" />
				</view>
				<view class="clickCount flex_col">
					<image v-if="!post.isThumbs" style="width: 30rpx;height: 30rpx;" @click.stop="updateThumbs(post.postId,1,index)" src="/static/thumbs.png"></image>
					<image v-if="post.isThumbs" style="width: 30rpx;height: 30rpx;" @click.stop="updateThumbs(post.postId,0,index)" src="/static/had-thumbs.png"></image>
					{{post.postClick}}
				</view>
			</view>
		</view>
		<view style="display: flex;justify-content: center;" v-if="!isExistPostList">粉丝练瑜伽太累，什么都没留下！</view>
	</view>
</template>

<script>
	import base from '@/common/base.js'
	export default {
		data() {
			return {
				user: null,
				focusId: 0,
				postList: [],
				isExistPostList: true
			}
		},
		onLoad(options) {
			this.getUser(options.focusId);
			this.getPostList(options.focusId);
		},
		methods: {
			getUser(focusId) {
				uni.request({
					url: base.urlPrefix + "yoga_app/focus/coachGetFansUser",
					data: {
						focusId: focusId
					},
					success: (res) => {
						this.user = res.data.object;
					}
				})
			},
			getPostList(focusId) {
				uni.request({
					url: base.urlPrefix + "yoga_app/focus/coachGetFansPostList",
					data: {
						focusId: focusId,
						coachId: base.coach.coachId
					},
					success: (res) => {
						if (res.data.code == "success") {
							this.postList = res.data.list;
						} else {
							this.isExistPostList = false;
						}
					}
				})
			},
			updateThumbs(postId, flag,index) {
				if (flag == 1) {
					this.postList[index].postClick++;
					this.postList[index].isThumbs = true;
				} else {
					this.postList[index].postClick--;
					this.postList[index].isThumbs = false;
				}
				uni.request({
					url: base.urlPrefix + 'yoga_app/thumbs-up/coachUpdateThumbs',
					data: {
						postId: postId,
						coachId: base.coach.coachId,
						postClick: this.postList[index].postClick,
						flag: Number(flag)
					}
				});
			},
			toShowPostDetail(postId){
				uni.navigateTo({
					url:"/pages/post/detail?postId="+postId
				})
			}
		}
	}
</script>

<style>
	.flex_col {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		justify-content: flex-start;
		align-items: center;
		align-content: center;
	}

	.border {
		border: #007AFF solid 1rpx;
	}

	/* 弹性盒子弹性容器 */
	.flex_col .flex_grow {
		width: 0;
		-webkit-box-flex: 1;
		-ms-flex-positive: 1;
		flex-grow: 1;
	}

	.flex_row .flex_grow {
		-webkit-box-flex: 1;
		-ms-flex-positive: 1;
		flex-grow: 1;
	}

	/* 弹性盒子允许换行 */
	.flex_col.flex_wrap {
		-ms-flex-wrap: wrap;
		flex-wrap: wrap;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.personMessage {
		color: #FFFFFF;
		text-align: center;
		font-size: small;
		margin-bottom: 10rpx;
	}

	.personSign {
		color: #FFFFFF;
		text-align: center;
		font-size: small;
		margin-bottom: 10rpx;
	}

	.fans {
		color: #FFFFFF;
		text-align: center;
		font-size: small;
	}

	.headerPortrait {
		width: 80upx;
		height: 80upx;
		margin: 0 auto;
		padding: 15upx;
		border: 1upx solid #333333;
		border-radius: 60upx;
		margin-top: 40upx;
		margin-left: 43%;
		background: #ffffff;
	}

	.smallHeaderPortrait {
		width: 30upx;
		height: 30upx;
		padding: 15upx;
		border-radius: 60upx;
		margin-top: 10upx;
		margin-left: 5%;
		background: #ffffff;
	}

	.list {
		background-color: #fff;
		font-size: 28upx;
		color: #333;
		user-select: none;
		touch-callout: none;
	}

	.postContent {
		font-size: small;
		margin-left: 5%;
	}

	.clickCount {
		margin-left: 85%;
		margin-bottom: 5upx;
		font-size: small;
	}
</style>
